package com.ruoyi.util;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * @program: back
 * @description:
 * @author: lvyq
 * @create: 2025-04-11 16:52
 **/

public class PinyinUtil {

        public static String getFirstLetter(String chinese) {
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(chinese.charAt(0));
            if (pinyinArray != null && pinyinArray.length > 0) {
                return String.valueOf(pinyinArray[0].charAt(0)).toUpperCase();
            } else {
                return String.valueOf(chinese.charAt(0)).toUpperCase();
            }
        }

        public static void main(String[] args) {
            String chinese = "中文";
            String firstLetter = getFirstLetter(chinese);
            System.out.println("拼音首字母为：" + firstLetter);
        }
}
